package cn.itcast.bos.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.IUserDao;
import cn.itcast.bos.domain.User;
import cn.itcast.bos.service.IUserService;
import cn.itcast.bos.utils.MD5Utils;

/**
 * 用户操作Service
 * @author zhaoqx
 *
 */
@Service
@Transactional
public class UserServiceImpl implements IUserService {
	@Resource
	private IUserDao userDao;

	//用户登录操作
	public User login(User model) {
		//将输入的明文的密码进行md5加密
		String password = MD5Utils.md5(model.getPassword());
		List<User> list = userDao.findByNamedQuery("findByUsernameAndPassword", model.getUsername(),password);
		if(list != null && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	//根据用户id修改密码
	public void editPassword(String id, String password) {
		//命名查询语句修改密码
		password = MD5Utils.md5(password);
		userDao.executeNamedQuery("editPassword", password,id);
	}
}
